package stream;

import cn.hutool.core.convert.Convert;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class GatherResult {
    // ignoreNUll
    static List<Map<String, Object>> sqlList = new ArrayList<>();
    public static void main(String[] args) {
        initSqlListData();

//        sqlList.stream().forEach(s-> System.out.println(s.toString()));
        System.out.println("过滤前");
        sqlList.parallelStream().forEachOrdered(System.out::println);
        sqlList = sqlList.stream().filter(s->streamFilter(s)).collect(Collectors.toList());
        System.out.println("过滤后");
        sqlList.parallelStream().forEachOrdered(System.out::println);



    }




    /**
     * 给 sqlList 里面塞值
     *
     */
    public static void initSqlListData(){
        //
        // List<Map<String, Object>> r = DbEngine.getJdbcTemplate().queryForList(sql.toString());
        // 模拟从数据库里面查出来的数据list集合
        // worker_wage 职业年金
        // old_wage 养老金

        Map<String, Object> map1 = new HashMap<>();
        map1.put("id", "1139005744356524033");
        map1.put("double_worker_wage", new Double(341.7));
        map1.put("decimal_worker_wage", Convert.toBigDecimal(new Double(341.7)));
        map1.put("double_old_wage",new Double(683.3));
        map1.put("decimal_old_wage",Convert.toBigDecimal(new Double(683.3)));


        sqlList.add(map1);

        Map<String, Object> map2 = new HashMap<>();
        map2.put("id", "1139005744360718337");
        map2.put("double_worker_wage", new Double(278.4));
        map2.put("decimal_worker_wage", Convert.toBigDecimal(new Double(278.4)));
        map2.put("double_old_wage", new Double(556.7));
        map2.put("decimal_old_wage", Convert.toBigDecimal(new Double(556.7)));
        sqlList.add(map2);

        Map<String, Object> map3 = new HashMap<>();
        map3.put("id", "1139005744369106944");
//        map3.put("double_worker_wage", new Double(234));
        map3.put("double_worker_wage", Double.valueOf(234));
//        map3.put("decimal_worker_wage", Convert.toBigDecimal(new Double(234)));
        map3.put("decimal_worker_wage", BigDecimal.valueOf(234));
//        map3.put("double_old_wage", new Double(467.9));
        map3.put("double_old_wage",Double.valueOf(467.9));
//        map3.put("decimal_old_wage", Convert.toBigDecimal(new Double(467.9)));
        map3.put("decimal_old_wage", BigDecimal.valueOf(467.9));
        sqlList.add(map3);
    }

    /**
     * double 相减和 bigDecimal相减
     * @param s
     */
    public static void subtractOperation(Map s){
        Double d = Convert.toDouble(s.get("double_worker_wage")) - Convert.toDouble(s.get("double_old_wage"));
        BigDecimal bigDecimal = Convert.toBigDecimal(s.get("decimal_worker_wage")).subtract(Convert.toBigDecimal(s.get("decimal_old_wage")));
        System.out.println("double:" + d + "\t" + "decimal: " + bigDecimal.toString());
    }


    public static boolean streamFilter(Map s){
//        return Convert.toDouble(s.get("double_worker_wage")) > 235
//                || Convert.toBigDecimal(s.get("decimal_worker_wage")).compareTo(BigDecimal.valueOf(468)) == 1;
        return Convert.toDouble(s.get("double_worker_wage")) > 235 && Convert.toBigDecimal(s.get("decimal_worker_wage")).compareTo(BigDecimal.valueOf(235)) == 1;
    }

}
